package cocoaas3.Titanium.UI{
	
	import jp.progression.casts.*;
	import jp.progression.commands.display.*;
	import jp.progression.commands.lists.*;
	import jp.progression.commands.managers.*;
	import jp.progression.commands.media.*;
	import jp.progression.commands.net.*;
	import jp.progression.commands.tweens.*;
	import jp.progression.commands.*;
	import jp.progression.data.*;
	import jp.progression.events.*;
	import jp.progression.loader.*;
	import jp.progression.*;
	import jp.nium.core.debug.Logger;
	import caurina.transitions.Tweener;
	import mx.events.DynamicEvent;

	import flash.display.*;
	import flash.net.*;
	import flash.geom.*;
	import flash.text.*;
	import flash.events.*


	public class OptionDialog extends Sprite{

		public static const CLICK:String = "click";

		[Embed(source="../../assets.swf", symbol='OptionDialog_design')]
		private var OptionDialog_design:Class;

		[Embed(source="../../assets.swf", symbol='optionDialog.Button_design')]
		private var Button_design:Class;


		private var design;
		public var title:String = "";
		public var cancel:uint;
		public var destructive:uint;
		public var options:Array = new Array();
		private var btns:Array = new Array();


		public function OptionDialog(){
			design = new OptionDialog_design();
		}

		public function show():void{
			design.main_mc.title_txt.text = title;

			var fmt:TextFormat = new TextFormat();
			fmt.bold = true;

			var lastButton;
			for( var i:uint=0; i<options.length; i++ ){
				var btn = new Button_design();
				btn.mouseChildren = false;
				btn.label_txt.defaultTextFormat = fmt;
				btn.label_txt.text = options[i];
				btn.x = 42;
				btn.y = i * 106 + 74;
				design.main_mc.addChild( btn );
				DefaultButton.getInstance().apply( btn );
				btn.addEventListener( MouseEvent.CLICK, _onButtonClick );
				btns.push( btn );
				lastButton = btn;
			}
			design.main_mc.bg_mc.height = lastButton.y + lastButton.height + 40;

			design.main_mc.y = CastDocument.bottom;
			CastDocument.stage.addChild( design );

			Tweener.addTween( design.main_mc, {y:CastDocument.bottom-design.main_mc.height, time:0.2, transition:"easeOutSine"} );
		}	


		public function hide():void{
			var slist = new SerialList();
			slist.addCommand(
				new DoTweener( design.main_mc, {y:CastDocument.bottom, time:0.2, transition:"easeInSine"} ),
				new RemoveChild( CastDocument.stage, design ),
			null);
			slist.execute();
		}


		private function _onButtonClick( e:MouseEvent ):void{
			hide();

			var btn = e.target;
			var index:int = btns.indexOf( btn );

			var evt:DynamicEvent = new DynamicEvent( OptionDialog.CLICK );
			evt.index = index;
			dispatchEvent( evt );
		}



	}
}



